Dominic Bordelon, Research Data Librarian
University Library System, University of Pittsburgh
dbordelon@pitt.edu
Services for the Pitt community:
Support areas and interests:
We will use the public repository for the dplyr R package as an example.
https://github.com/tidyverse/dplyr
Note:
tidyverse/dplyr)Using the green Code button, you can download a zip of the repository, or clone it to your computer using the git clone command.
Whenever the source (or “origin”) repository updates on github.com, downstream clones may afterwards fetch and integrate updates.
Note Issues tab, Code button, and file listing of the tidyverse/dplyr repository.
The repository’s changes over time are documented as snapshots or commits.
ea6fb94 (for example)A series of commits in sequence is a branch. The user creates a branch to begin a new “line of development,” choosing an existing commit as the starting point of the branch.
A merge occurs when branch B pulls in a commit from branch A and combines them into a new commit on branch B.
💡 One’s current location in the graph is called HEAD. Any commit (node) of the graph may be checked out to view the repository state at that moment. HEAD moves to the checked-out commit.
💡 Aim for each commit to be “atomic,” i.e., accomplishing one unit of work or task.
💡 Aim for each branch to segment out a bounded part of the project. Branches may be of any length.
Commits are prominent on GH: they appear on file listings, to show the message+age of the last edit (see next slide). The message (as well as any hash) links to the commit.
Branches are accessed at the top left. Switching to a branch changes the file view.
For dplyr repository, note:
Example file listing. The highlighted file, codecov.yml, was last updated 3 years ago in a commit whose message was “Update gitHub actions (#5188)”. Clicking the message shows the page for the commit (full description + files changed + file diffs). #5188 refers and links to an Issue.
Branch button expanded. Click on a branch name to switch to it. Click on commits, right, to see a log of the current branch’s commits.
The local clone of the repo on your computer is configured to “remember” the GH instance. The GH instance is configured as a remote. In particular, it is a special remote called origin.
You may run git pull anytime, to fetch and merge new commits that have been posted to origin since you last checked. (git fetch downloads commits without merging them automatically, for inspection prior to merging.)
There won’t be anything to pull yet, since you’ve only just cloned the repo, but pulling becomes very important when:
origin concurrently with you.We will practice committing, branching, and merging.
HEAD is at c0, the initial commit on branch b0. Use the git commit command to make some commits.git branch command to create a new branch.git checkout b1 to checkout branch b1. Make some commits to the new branch.b0 and then make a commit. Where does the commit appear?b1. Update b1 by using merge on the b0 commit that you just made.b1. Then switch back to b0 and merge b1 back into b0.git monitors the project directory for changes. Changes are added to the staging area by the user. Once all desired changes are staged for the current action or task, the user commits them to the repository.
Important commands:
git init |
Initialize a git repository in the current directory |
git status |
Check status of dir’s git repo and staging area |
git add |
Add file(s) to staging area |
git commit -m "message" |
Commit staged files with a message |
git branch |
Create a branch |
git checkout 12e45f |
Check out commit #12e45f |
git checkout mybranch |
Check out latest commit on mybranch |
git merge mybranch |
Merge mybranch into the current branch |
git init.git status to see that you have 1+ untracked file(s).git add.git commit -m "my message" to commit the staged files, with your desired message.git status to confirm that the staging area is empty again.git log to see the record of your commit.In GitHub, click “Create New Repository.” This will be a placeholder. Follow the directions on the next screen after creating, to push (upload) your repo into this placeholder.
After pushing, you should see your latest commit online. Woohoo!
If there are files you want to physically keep in the folder, yet exclude from git’s tracking—for example, a file with API credentials—list it in a plain text file named .gitignore.
Or you can look for git and GitHub integrations in software you already use, for example: git in VS Code, git in RStudio, git in PyCharm
Or you can delve into one of these topics:
Git and GitHub: Solo Usage